#include "LED.h"

module LEDC {
	provides interface LEDControl;
	uses interface Leds;
}

implementation {
	void On(LEDState state) {
		switch(state) {
			case LEDState_Send : call Leds.led2On();
			break;

			case LEDState_Receive : call Leds.led1On();
			break;

			case LEDState_Retransmit : call Leds.led0On();
			call Leds.led1On();
			break;

			case LEDState_ModeSend : call Leds.set(4);
			break;

			case LEDState_ModePassive : call Leds.set(1);
			break;

			case LEDState_ModeReceive : call Leds.set(2);
			break;

			case LEDState_Error : call Leds.led0On();
			break;

			default : call Leds.set(0);
			break;
		}
	}

	void Off(LEDState state) {
		switch(state) {
			case LEDState_Send : call Leds.led2Off();
			break;

			case LEDState_Receive : call Leds.led1Off();
			break;

			case LEDState_Retransmit : call Leds.led0Off();
			call Leds.led1Off();
			break;

			case LEDState_ModeSend : call Leds.led2Off();
			break;

			case LEDState_ModePassive : call Leds.led0Off();
			break;

			case LEDState_ModeReceive : call Leds.led1Off();
			break;

			case LEDState_Error : call Leds.led0Off();
			break;

			case LEDState_AllOff : call Leds.set(0);
			break;

			default : call Leds.set(0);
			break;
		}
	}

	async command void LEDControl.On(LEDState state) {
		On(state);
	}

	async command void LEDControl.Off(LEDState state) {
		Off(state);
	}

	async command void LEDControl.Test(int mask) {
		call Leds.set(mask);
	}
}